#include "Geometry/CustomObjectSection.h"
#include "Framework/StableHeaders.h"
#include "Geometry/CustomObject.h"
#include "Graphics/VertexData.h"
#include "Graphics/MaterialManager.h"
#include "Graphics/Material.h"

namespace tyro
{
	namespace Geometry
	{


		CustomObjectSection::CustomObjectSection( CustomObject* parent, const String& materialName, Graphics::MaterialManager* matMgr, RenderType renderType, const String & groupName /*= IO::ResourceGroupManager::DEFAULT_GROUP_NAME*/ )
			: parent(parent)
			, materialName(materialName)
			, groupName(groupName)
			, is32BitIndices(false)
			, activeMaterial(0)
			, matManager(matMgr)
		{
			renderOperation.renderType = renderType;
			renderOperation.vertexData = new Graphics::VertexData();
			renderOperation.vertexData->vertexCount = 0;
		}


		Graphics::IRenderOperation* CustomObjectSection::GetRenderOperation( void )
		{
			return &renderOperation;
		}

		void CustomObjectSection::GetRenderOperation( Graphics::IRenderOperation& op )
		{
			op = renderOperation;	
		}

		bool CustomObjectSection::Is32BitIndices() const
		{
			return is32BitIndices;
		}

		void CustomObjectSection::Set32BitIndex( bool is32BitIndices )
		{
			this->is32BitIndices = is32BitIndices;
		}

		void CustomObjectSection::GetWorldTransforms( Math::Matrix4f* mat ) const
		{
			mat[0] = parent->GetParentWorldTransform(); 

		}

		const Graphics::MaterialPtr& CustomObjectSection::GetMaterial( void ) const
		{
			// Check to see material is loaded
			if (activeMaterial.IsNull())
			{
				// Load material if not
				activeMaterial = matManager->Load(materialName, groupName);

			}
			return activeMaterial;
		}

		
		

	}
}


